import Vue from 'vue'
import vueRouter from 'vue-router'
Vue.use(vueRouter)
import Home from '../components/routerCom/Home'
import Topic from '../components/routerCom/Topic'
import Main from '../components/routerCom/Main'
import ErrorCom from '../components/routerCom/Error'
import Children from '../components/routerCom/Children'

let routes = [
    {
        path: '/home/:i',
        component: Home,
        name: 'Home',
        props: true,
        children: [
            {
                path: 'children',
                component: Children,
                name: 'Children'
            }
        ]
    },
    {
        path: '/topic',
        component: Topic,
        name: 'Topic',
        beforeEnter: (to, from, next) => {
            if(confirm('确定要跳转么？')){
                next()
            }else{
                next(false)
            }
        }
    },
    {
        path: '/main',
        component: Main,
        name: 'Main'
    },
    {
        path: '*',
        component: ErrorCom,
    }
]
let router = new vueRouter({
    routes
})
// router.beforeEach((to, from, next) => {
//     if (to.name === 'Home') {
//         next(false)
//         return
//     }
//     next()
// })

router.afterEach((to, from) => {
    console.log(to);
    console.log(from);
})
export default router